<?php
/*
 * TODO 基础分页的相同代码封装，是前台代码更少
 * @param $m 模型，引用传递
 * @param $where 查询条件
 * @param int $pagesize 每页查询条数
 * @return \Think\Page
 */

function getpage(&$m,$where,$pagesize=5){
	$m1 = clone $m;//浅赋值一个模型
	$count = $m->where($where)->count();//连贯操作后会对join等操作进行重置
	$m = $m1;//为保持在为定的连贯操作，浅复制一个模型
	$p = new Think\Page($count,$pagesize);
	$p->lastSuffix = false;
	$p->setConfig('header', '<li class="rows">共<b>%TOTAL_ROW%</b>条记录&nbsp;&nbsp;
			第<b>%NOW_PAGE%</b>页/共<b>%TOTAL_PAGE%</b>页</li>');
	$p->setConfig('prev', '上一页');
    $p->setConfig('next', '下一页');
    $p->setConfig('last', '末页');
    $p->setConfig('first', '首页');
    $p->setConfig('theme', '%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
    $p->parameter = I('get.');
    $m->limit($p->firstRow,$p->listRows);

    return $p;
}

//检测输入数据中是否含有空格及特殊字符，并处理
//@return 处理后的数据
function test_input($data) {
	$data = trim($data);
	$data = stripslashes($data);
	$data = htmlspecialchars($data);
	return $data;
}

//上传图片的格式设置
//@return \Think\Upload
function upload_img(){
    $upload = new Think\Upload();
    $upload->maxSize = 3145728;
    $upload->exts = array('jpg','gif','png','jpeg','pjpeg');
    $upload->rootPath ='./Public/images/uppic/';
    $upload->savePath = '';
    return $upload;
}

//日期格式判断
//@return bool
function check_date($time){
    $check_date = '';
    if(preg_match("^d{4}-d{2}-d{2} d{2}:d{2}:d{2}$\s", $time)){
        $check_date = true;
    }else{
        $check_date = false;
    }
    return $check_date;
}
?>




























